// auto_tester.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>
#include "ShellAPI.h"

//SHSTDAPI_(HINSTANCE) ShellExecuteA(HWND hwnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, INT nShowCmd);

void do_test(char *exe_to_test,char *path_to_test,char *name_of_test,char *file_of_test);
int i=0;

int _tmain(int argc, _TCHAR* argv[])
{


	char exe_to_test[500];//path and name of file to test
	strcpy(exe_to_test,argv[1]);
	char path_to_test[200];
	strcpy(path_to_test,argv[2]);
	char main_test[120];
	sprintf(main_test,"%s\\tests.txt",path_to_test);
	FILE *tst_file=fopen(main_test,"rt");
	if(!tst_file) {printf("Missing main test file %s",main_test);exit(1);}
	char name_of_test[300];
	char file_of_test[300];
	while(!feof(tst_file))
	{
		fgets(name_of_test,300,tst_file);
		fgets(file_of_test,300,tst_file);
		do_test(exe_to_test,path_to_test,name_of_test,file_of_test);
	}
	fclose(tst_file);
	return 0;
}


void do_test(char *exe_to_test,char *path_to_test,char *name_of_test,char *file_of_test)
{
	char stin[200];
	char stout[200];
	char buffer[200];
	char params[200] = "< test01.txt >  d:\\templab2.txt";
	sprintf(stin,"%s\\%s",path_to_test,file_of_test);
	sprintf(stout,"%06d.tst",i);
	printf("%s %s \n", "stin = ", stin);
	printf("%s %s \n", "stout = ", stout);
	//sprintf(dest, );
	//spawnlp(_P_WAIT,exe_to_test,exe_to_test, "-n < test01.txt > 123.txt", NULL);
	//spawnl(_P_WAIT,exe_to_test,exe_to_test, "-n", " < ",stin," >> ",stout,NULL);
	//sprintf(params, "%s %s %s %s %s", "-n", "<", stin, ">", stout);
	printf("%s %s \n", "params = ", params);
	ShellExecuteA(0, "open", exe_to_test, params, "", SW_SHOWNORMAL);
i++;
}